package com.singlemountain.gcommerce.utils;

import com.google.gson.Gson;
import com.singlemountain.gcommerce.domain.image.Imaged;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: SMT01
 * Date: 12-2-23
 * To change this template use File | Settings | File Templates.
 */
public class TransferImageUtils {
    public static ImageJson imageDomain2Json(Imaged imaged) {
        ImageJson imageJson = new ImageJson();
        imageJson.setName(imaged.getName());
        imageJson.setDelete_type("DELETE");
        imageJson.setThumbnail_url("/image/" + imaged.getId());
        imageJson.setUrl("/image/" + imaged.getId());
        imageJson.setDelete_url("/image/" + imaged.getId());
        imageJson.setSize(imaged.getBig().length);
        return imageJson;
    }

    public static List<ImageJson> imageDomain2JsonList(Imaged imaged) {
        List<ImageJson> imageJsons = new ArrayList<ImageJson>();
        imageJsons.add(imageDomain2Json(imaged));
        return imageJsons;
    }

    public static String imageDomain2JsonListString(Imaged imaged) {
        Gson gson = new Gson();
        return gson.toJson(imageDomain2JsonList(imaged));
    }

    public static List<ImageJson> imageDomain2Json(List<Imaged> imageds) {
        List<ImageJson> imageJsons = new ArrayList<ImageJson>();
        for (Imaged imaged : imageds) {
            ImageJson imageJson = imageDomain2Json(imaged);
            imageJsons.add(imageJson);
        }
        return imageJsons;
    }
}
